import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:im_module/manager/ImChatManager.dart';
import 'package:im_module/widget/AppBarBackground.dart';

class UpdateNameWidget extends StatefulWidget {
  String groupName;
  String groupID;

  UpdateNameWidget(this.groupID, this.groupName);

  @override
  _UpdateNameWidgetState createState() => _UpdateNameWidgetState();
}

class _UpdateNameWidgetState extends State<UpdateNameWidget> {
  late TextEditingController _controller;

  @override
  void initState() {
    super.initState();
    _controller = TextEditingController(text: "${widget.groupName}");
  }

  @override
  Widget build(BuildContext context) {
    return AppBarBackground(
      child: Scaffold(
        appBar: AppBar(title: Text("修改群聊名"),centerTitle: true,),
        body: Container(
          color: Colors.white,
          child: Padding(
            padding: const EdgeInsets.only(top: 50),
            child: Column(
              children: [
                Text(
                  "修改群聊名称",
                  style: TextStyle(fontSize: 18),
                ),
                SizedBox(
                  height: 15,
                ),
                Text(
                  "修改群聊名称后，将在群里通知\n其他成员",
                  textAlign: TextAlign.center,
                  style: TextStyle(
                    fontSize: 14,
                  ),
                ),
                SizedBox(
                  height: 10,
                ),
                Container(
                  margin: EdgeInsets.symmetric(horizontal: 30),
                  child: TextField(
                    controller: _controller,
                    decoration: InputDecoration(hintText: '请输入群聊名称'),
                    inputFormatters: [new LengthLimitingTextInputFormatter(10)],
                  ),
                ),
                SizedBox(
                  height: 10,
                ),
                TextButton(
                  onPressed: () {
                    ImChatManager()
                        .updateGroupName(widget.groupID, _controller.text)
                        .then((value){
                          if(value){
                            Navigator.pop(context,_controller.text);
                          }
                    });
                  },
                  child: Container(
                    width: 80,
                    height: 35,
                    alignment: Alignment.center,
                    /*decoration: BoxDecoration(
                      border: Border.all(color: Colors.black26, width: 0.5),
                      shape: BoxShape.rectangle
                    ),*/
                    child: Text("修改群名"),
                  ),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}
